package android.support.v4.view;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.widget.TextView;
import java.lang.ref.WeakReference;

public class PagerTitleStrip extends ViewGroup
  implements av
{
  private static final int[] n = { 16842804, 16842901, 16842904, 16842927 };
  private static final int[] o = { 16843660 };
  private static final x q;
  ViewPager a;
  TextView b;
  TextView c;
  TextView d;
  int e;
  private int f;
  private float g;
  private int h;
  private int i;
  private boolean j;
  private boolean k;
  private final w l;
  private WeakReference m;
  private int p;

  static
  {
    if (Build.VERSION.SDK_INT >= 14)
    {
      q = new z();
      return;
    }
    q = new y();
  }

  public PagerTitleStrip(Context paramContext)
  {
    this(paramContext, null);
  }

  public PagerTitleStrip(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    this.f = -1;
    this.g = -1.0F;
    this.l = new w(this, 0);
    TextView localTextView = new TextView(paramContext);
    this.b = localTextView;
    addView(localTextView);
    localTextView = new TextView(paramContext);
    this.c = localTextView;
    addView(localTextView);
    localTextView = new TextView(paramContext);
    this.d = localTextView;
    addView(localTextView);
    paramAttributeSet = paramContext.obtainStyledAttributes(paramAttributeSet, n);
    int i1 = paramAttributeSet.getResourceId(0, 0);
    if (i1 != 0)
    {
      this.b.setTextAppearance(paramContext, i1);
      this.c.setTextAppearance(paramContext, i1);
      this.d.setTextAppearance(paramContext, i1);
    }
    int i2 = paramAttributeSet.getDimensionPixelSize(1, 0);
    if (i2 != 0)
    {
      float f1 = i2;
      this.b.setTextSize(0, f1);
      this.c.setTextSize(0, f1);
      this.d.setTextSize(0, f1);
    }
    if (paramAttributeSet.hasValue(2))
    {
      i2 = paramAttributeSet.getColor(2, 0);
      this.b.setTextColor(i2);
      this.c.setTextColor(i2);
      this.d.setTextColor(i2);
    }
    this.i = paramAttributeSet.getInteger(3, 80);
    paramAttributeSet.recycle();
    this.e = this.c.getTextColors().getDefaultColor();
    this.p = 153;
    i2 = this.p << 24 | this.e & 0xFFFFFF;
    this.b.setTextColor(i2);
    this.d.setTextColor(i2);
    this.b.setEllipsize(TextUtils.TruncateAt.END);
    this.c.setEllipsize(TextUtils.TruncateAt.END);
    this.d.setEllipsize(TextUtils.TruncateAt.END);
    if (i1 != 0)
    {
      paramAttributeSet = paramContext.obtainStyledAttributes(i1, o);
      bool = paramAttributeSet.getBoolean(0, false);
      paramAttributeSet.recycle();
    }
    if (bool)
    {
      a(this.b);
      a(this.c);
      a(this.d);
    }
    while (true)
    {
      this.h = (int)(paramContext.getResources().getDisplayMetrics().density * 16.0F);
      return;
      this.b.setSingleLine();
      this.c.setSingleLine();
      this.d.setSingleLine();
    }
  }

  private static void a(TextView paramTextView)
  {
    q.a(paramTextView);
  }

  final void a(int paramInt, float paramFloat, boolean paramBoolean)
  {
    int i1;
    int i2;
    int i3;
    int i4;
    int i5;
    int i6;
    int i7;
    int i8;
    int i9;
    int i10;
    int i11;
    int i12;
    int i13;
    if (paramInt != this.f)
    {
      a(paramInt, this.a.a());
      this.k = true;
      i4 = this.b.getMeasuredWidth();
      i9 = this.c.getMeasuredWidth();
      i3 = this.d.getMeasuredWidth();
      i8 = i9 / 2;
      i5 = getWidth();
      i1 = getHeight();
      i7 = getPaddingLeft();
      i6 = getPaddingRight();
      paramInt = getPaddingTop();
      i2 = getPaddingBottom();
      i10 = i6 + i8;
      float f2 = 0.5F + paramFloat;
      float f1 = f2;
      if (f2 > 1.0F)
        f1 = f2 - 1.0F;
      i8 = i5 - i10 - (int)(f1 * (i5 - (i7 + i8) - i10)) - i8;
      i9 = i8 + i9;
      i12 = this.b.getBaseline();
      i11 = this.c.getBaseline();
      i10 = this.d.getBaseline();
      i13 = Math.max(Math.max(i12, i11), i10);
      i12 = i13 - i12;
      i11 = i13 - i11;
      i10 = i13 - i10;
      i13 = this.b.getMeasuredHeight();
      int i14 = this.c.getMeasuredHeight();
      int i15 = this.d.getMeasuredHeight();
      i13 = Math.max(Math.max(i13 + i12, i14 + i11), i15 + i10);
      switch (this.i & 0x70)
      {
      default:
        i2 = paramInt + i12;
        i1 = paramInt + i11;
        paramInt += i10;
      case 16:
      case 80:
      }
    }
    while (true)
    {
      while (true)
      {
        this.c.layout(i8, i1, i9, this.c.getMeasuredHeight() + i1);
        i1 = Math.min(i7, i8 - this.h - i4);
        this.b.layout(i1, i2, i4 + i1, this.b.getMeasuredHeight() + i2);
        i1 = Math.max(i5 - i6 - i3, this.h + i9);
        this.d.layout(i1, paramInt, i1 + i3, this.d.getMeasuredHeight() + paramInt);
        this.g = paramFloat;
        this.k = false;
        return;
        if ((!(paramBoolean)) && (paramFloat == this.g))
          return;
      }
      paramInt = (i1 - paramInt - i2 - i13) / 2;
      i2 = paramInt + i12;
      i1 = paramInt + i11;
      paramInt += i10;
      continue;
      paramInt = i1 - i2 - i13;
      i2 = paramInt + i12;
      i1 = paramInt + i11;
      paramInt += i10;
    }
  }

  final void a(int paramInt, v paramv)
  {
    if (paramv != null)
      paramv.a();
    this.j = true;
    this.b.setText(null);
    this.c.setText(null);
    this.d.setText(null);
    int i4 = getWidth();
    int i5 = getPaddingLeft();
    int i6 = getPaddingRight();
    int i1 = getHeight();
    int i2 = getPaddingTop();
    int i3 = getPaddingBottom();
    i4 = View.MeasureSpec.makeMeasureSpec((int)((i4 - i5 - i6) * 0.8F), -2147483648);
    i1 = View.MeasureSpec.makeMeasureSpec(i1 - i2 - i3, -2147483648);
    this.b.measure(i4, i1);
    this.c.measure(i4, i1);
    this.d.measure(i4, i1);
    this.f = paramInt;
    if (!(this.k))
      a(paramInt, this.g, false);
    this.j = false;
  }

  final void a(v paramv1, v paramv2)
  {
    if (paramv1 != null)
    {
      paramv1.b(this.l);
      this.m = null;
    }
    if (paramv2 != null)
    {
      paramv2.a(this.l);
      this.m = new WeakReference(paramv2);
    }
    if (this.a == null)
      return;
    this.f = -1;
    this.g = -1.0F;
    a(this.a.b(), paramv2);
    requestLayout();
  }

  protected void onAttachedToWindow()
  {
    super.onAttachedToWindow();
    Object localObject = getParent();
    if (!(localObject instanceof ViewPager))
      throw new IllegalStateException("PagerTitleStrip must be a direct child of a ViewPager.");
    localObject = (ViewPager)localObject;
    v localv = ((ViewPager)localObject).a();
    ((ViewPager)localObject).b(this.l);
    ((ViewPager)localObject).a(this.l);
    this.a = ((ViewPager)localObject);
    if (this.m != null);
    for (localObject = (v)this.m.get(); ; localObject = null)
    {
      a((v)localObject, localv);
      return;
    }
  }

  protected void onDetachedFromWindow()
  {
    super.onDetachedFromWindow();
    if (this.a == null)
      return;
    a(this.a.a(), null);
    this.a.b(null);
    this.a.a(null);
    this.a = null;
  }

  protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    float f1 = 0.0F;
    if (this.a == null)
      return;
    if (this.g >= 0.0F)
      f1 = this.g;
    a(this.f, f1, true);
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    int i3 = View.MeasureSpec.getMode(paramInt1);
    int i1 = View.MeasureSpec.getMode(paramInt2);
    int i2 = View.MeasureSpec.getSize(paramInt1);
    paramInt2 = View.MeasureSpec.getSize(paramInt2);
    if (i3 != 1073741824)
      throw new IllegalStateException("Must measure with an exact width");
    paramInt1 = 0;
    Drawable localDrawable = getBackground();
    if (localDrawable != null)
      paramInt1 = localDrawable.getIntrinsicHeight();
    i3 = getPaddingTop() + getPaddingBottom();
    int i4 = View.MeasureSpec.makeMeasureSpec((int)(i2 * 0.8F), -2147483648);
    int i5 = View.MeasureSpec.makeMeasureSpec(paramInt2 - i3, -2147483648);
    this.b.measure(i4, i5);
    this.c.measure(i4, i5);
    this.d.measure(i4, i5);
    if (i1 == 1073741824)
    {
      setMeasuredDimension(i2, paramInt2);
      return;
    }
    setMeasuredDimension(i2, Math.max(paramInt1, this.c.getMeasuredHeight() + i3));
  }

  public void requestLayout()
  {
    if (this.j)
      return;
    super.requestLayout();
  }
}